package com.chixing.dao.impl;

import com.chixing.dao.DepartmentDao;
import com.chixing.dao.JdbcTemplate;
import com.chixing.pojo.Department;

public class DepartmentDaoImpl implements DepartmentDao {
    private JdbcTemplate<Department> jdbcTemplate;

    public DepartmentDaoImpl(JdbcTemplate<Department> jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public Department selectByPrimaryKey(int primarykey) {
        String sql ="select deptno,dname,loc from dept where deptno = ?";//int
        Object args = primarykey;
       return  jdbcTemplate.queryForObject(sql,primarykey);
    }

    @Override
    public int insert(Department department) {
        String sql ="insert into dept values(?,?,?)";
        Object[] args = {department.getDeptNo(),department.getDeptName(),department.getDeptLocation()};
       return jdbcTemplate.update(sql,args);

    }

    @Override
    public int update(Department department) {
        String sql ="update dept set dname = ? , loc = ? where deptno =?";
        Object[] args = {department.getDeptName(),department.getDeptLocation(),department.getDeptNo()};
        return jdbcTemplate.update(sql,args);
    }

    @Override
    public int delete(int primarykey) {
        String sql ="delete from dept where deptno = ?";
        Object[] args = {primarykey};
        return jdbcTemplate.update(sql,args);
    }
}
